package leetcode.leetcode_108;

class Solution {
    public TreeNode sortedArrayToBST(int[] nums) {
        TreeNode build = build(nums, 0, nums.length - 1);
        return build;

    }
    public TreeNode build(int [] nums , int left ,int right){
        if (left>right) return null;
        if (left == right ) return new TreeNode(nums[left],null,null);
        int mid = left + (right-left)/2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = build(nums,left ,mid-1);
        node.right = build(nums,mid+1,right);
        return node;
    }
}